package work;

import java.util.ArrayList;
import java.util.List;

public class StaticDemo {

    public static void main(String[] args) {
        getResultByProvince();
        getResultByStore();
    }

    private static void getResultByStore() {
        List<List<WorkOrderBean>> nowOrders = getWorkOrdersFromDB("2020-09-07");
        List<List<WorkOrderBean>> historyOrders = getWorkOrdersFromDB("all");

        List<Result> results = calculateResult(historyOrders, nowOrders, "门店");

        exportToExcel(results, "d:/tmp1.xls");
    }

    private static void getResultByProvince() {
        List<List<WorkOrderBean>> nowOrders = getWorkOrdersFromDB("2020-09-07");
        List<List<WorkOrderBean>> historyOrders = getWorkOrdersFromDB("all");

        List<Result> results = calculateResult(historyOrders, nowOrders, "腰部流量");

        exportToExcel(results, "d:/tmp.xls");
    }

    private static void exportToExcel(List<Result> results, String filePath) {

    }

    private static List<List<WorkOrderBean>> getWorkOrdersFromDB(String date) {
        return null;
    }


    public static List<Result> calculateResult(List<List<WorkOrderBean>> history, List<List<WorkOrderBean>> input, String title) {
        List<Result> results = new ArrayList<>();
        for (int i = 0; i < input.size(); i++) {
            Result result = new Result();
            List<WorkOrderBean> inputElement = input.get(i);
            List<WorkOrderBean> historyElement = history.get(i);
            int nowFinishCount = getCountByStatus(inputElement, 4);
            int nowTotalCount = getCountByStatus(inputElement, -1);
            double nowFinishRate = (double) nowFinishCount / nowTotalCount;
            result.nowIncreaseCount = nowTotalCount;
            result.nowFinishCount = nowFinishCount;
            result.nowFinishRate = nowFinishRate;
            results.add(result);
        }

        return results;
    }

    private static int getCountByStatus(List<WorkOrderBean> input, int status) {
        int count = 0;
//        计算总量
        if (status == -1) {
            return input.size();
        }


        for (WorkOrderBean workOrderBeans : input) {
            if (workOrderBeans.status == status) {
                count++;
            }
        }
        return count;
    }
}
